<template>
  <view class="box">
    <view
      class="box_details"
      v-for="(item, index) in listv"
      :key="index"
      @click="goDetail(item)"
    >
      <view
        v-show="!flag"
        class="item_left_clickView"
        @click.stop="change(item)"
      >
        <image
          v-if="!item.clickable"
          class="item_left_click"
          src="../../../static/images/my/icon_grzy_quanxuan.png"
          mode=""
        ></image>
        <image
          v-else
          class="item_left_clickable"
          src="../../../static/images/my/icon_grzy_xc_xuanzhong.png"
          mode=""
        ></image>
      </view>

      <view
        class="Preview_style"
        v-if="my_level_id < item.grade_auth && tab_id != 1"
        @click.stop="goMember"
      >
        该内容仅支持{{
          item.grade_auth == 1
            ? "元气驿站"
            : item.grade_auth == 2
            ? "启初梦谷"
            : item.grade_auth == 3
            ? "青空天台"
            : item.grade_auth == 4
            ? "无极云顶"
            : item.grade_auth == 5
            ? "返朴归源"
            : ""
        }}及以上行者查看
      </view>

      <view class="all_detail" v-else>
        <view
          class="details_left"
          v-if="(item.file && item.file.length) || item.file_url"
        >
          <image :src="item.file_url" mode="" v-if="item.file_url"></image>
          <image
            :src="
              item.file[0].file_type == 10
                ? item.file[0].url
                : item.file[0].url_img
            "
            mode=""
            v-else
          ></image>
        </view>
        <view class="details_right" v-if="!item.msg">
          <view class="right_title" v-if="item.title || item.name">
            {{ item.title || item.name }}
          </view>
          <view class="right_text1" v-if="!item.title && !item.name">
            {{ item.content || item.jieshao }}
          </view>
          <view class="right_text" v-else>
            {{ item.content || item.jieshao }}
          </view>

          <view class="right_time">
            <image
              src="@/static/images/icon_sy_jinrigengxin_shijian.png"
              mode=""
            ></image>
            <text>{{ item.create_time || item.update_time   }}</text>
          </view>
        </view>
        <view v-else style="color: white">{{ item.msg }}</view>
      </view>
    </view>

    <view class="bottom" v-show="!flag">
      <view class="bottom_left">
        <view @click="changeClick">
          <image
            v-if="!clickableAll"
            class="item_left_click"
            src="../../../static/images/my/icon_grzy_quanxuan.png"
            mode=""
          ></image>
          <image
            v-else
            class="item_left_click"
            src="../../../static/images/my/icon_grzy_xc_xuanzhong.png"
            mode=""
          ></image>
        </view>
        <view class="bottom_left_text">全选</view>
      </view>
      <view class="bottom_right" @click="deleteFn">删除</view>
    </view>

    <u-modal
      :show="show"
      :title="title"
      :content="content"
      confirmColor="#55B877"
      :closeOnClickOverlay="true"
      @confirm="confirm"
      @close="close"
      @cancel="cancel"
      :showCancelButton="true"
    ></u-modal>

    <view class="empty_view" v-if="listv && listv.length == 0">
      <image
        class="item_left_clickable"
        src="../../../static/images/my/kong.png"
        mode=""
      ></image>
      <view v-if="from == 'history'">您还没有历史记录~</view>
      <view v-else>当前没有相关数据，请查看其他分类或功能。</view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    flag: {
      type: Boolean,
      default: true,
    },
    list: {
      type: Array,
      default: () => [],
    },
    from: {
      type: String,
      default: "",
    },
    my_level_id: {
      type: Number,
      default: 0,
    },
    tab_id: {
      type: Number,
      default: 1,
    },
  },
  watch: {
    list: {
      deep: true, // 深度监听每一个属性值, 如果是对象可以深度监听
      immediate: true, // 进入页面后立即自动调用handler函数
      handler(newValue) {
        this.listv = newValue;
        if (this.listv) {
          for (let i = 0; i < this.listv.length; i++) {
            this.listv[i].clickable = false;
          }
        }
        console.log(this.listv, "newList");
      },
    },
  },
  created() {},
  data() {
    return {
      listv: [],
      clickableAll: false,
      show: false,
      title: "确认删除",
      content: "确认删除选中内容？",
    };
  },
  methods: {
    change(item) {
      this.$forceUpdate();
      item.clickable = !item.clickable;
      // 判断是否全选
      let all = true;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == false) {
          all = false;
        }
      }
      if (all) {
        this.clickableAll = true;
      } else {
        this.clickableAll = false;
      }
    },
    // 跳会员页面
    goMember() {
      uni.navigateTo({
        url: `/pages/member/index`,
      });
    },
    goDetail(item) {
      if (this.tab_id == 1) {
        // 1奥义  2大成
        // if(item.type == 1){
        //   // 跳飞离洞

        // } else {

        // }
        uni.navigateTo({
          url: `/pages/training/detail?id=${item.id}&type=${item.type}`,
        });
      } else {
        if (item.type == 1) {
          // 跳飞离洞
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=fei&currentId=${item.id}&from=wei`,
          });
        } else if (item.type == 2) {
          // 跳灵感塔
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=ling&currentId=${item.id}&from=wei`,
          });
        } else if (item.type == 3) {
          // 跳诗心园
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=shi&currentId=${item.id}&from=wei`,
          });
        } else if (item.type == 4) {
          // 跳文心岛
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=wen&currentId=${item.id}&from=wei`,
          });
        } else if (item.type == 5) {
          // 跳共创
          uni.navigateTo({
            url: `/pages/distinguish/discussionGroup?id=${item.id}`,
          });
        } else if (item.type == 6) {
          // 跳游记
          uni.navigateTo({
            url: `/pages/detail/flyDetail?detailType=youji&currentId=${item.id}&from=wei`,
          });
        }
      }
    },
    changeClick() {
      this.clickableAll = !this.clickableAll;
      if (this.clickableAll) {
        for (let i = 0; i < this.listv.length; i++) {
          this.listv[i].clickable = true;
        }
      } else {
        for (let i = 0; i < this.listv.length; i++) {
          this.listv[i].clickable = false;
        }
      }
    },
    confirm() {
      this.show = false;
      let arr = [];
      let num = 0;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == true) {
          arr.push(this.listv[i].history_id);
          num++;
        }
      }
      console.log(arr, "数组");
      this.deletFn(arr);
    },
    close() {
      this.show = false;
    },
    cancel() {
      this.show = false;
    },
    // 删除按钮
    deleteFn() {
      let isTrue = true;
      for (let i = 0; i < this.listv.length; i++) {
        if (this.listv[i].clickable == true) {
          isTrue = false;
        }
      }
      if (isTrue == true) {
        uni.$u.toast("您还未选择内容");
      } else {
        this.show = true;
      }
    },
    // 删除接口
    deletFn(arr) {
      this.$http
        .historyDel_his_jinri({ ids: arr })
        .then((res) => {
          uni.$u.toast(res.message);
          this.show = false;
          setTimeout(() => {
            this.$emit("updateDataJinRi");
          }, 1000);
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
  },
};
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
}
.box_details {
  width: 100%;
  //   height: 180rpx;
  display: flex;
  margin-top: 40rpx;
  align-items: center;
  .all_detail {
    display: flex;
  }
  .Preview_style {
    width: 100%;
    height: 150rpx;
    border-radius: 16rpx;
    background: rgba(105, 113, 151, 0.7);
    // margin-top: 24rpx;
    text-align: center;
    line-height: 150rpx;
    color: white;
  }
  .details_left {
    width: 180rpx;
    height: 180rpx;
    margin-right: 32rpx;
    image {
      width: 100%;
      height: 100%;
      border-radius: 8rpx;
    }
  }

  .details_right {
    flex: 1;
    // padding-left: 32rpx;
    // margin-left: 32rpx;
    box-sizing: border-box;
    position: relative;
    height: 180rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .right_title {
      width: 100%;
      font-size: 32rpx;
      font-family: PingFang SC-Bold, PingFang SC;
      font-weight: 600;
      color: #eeeeee;
      margin-bottom: 17rpx;
    }

    .right_text {
      width: 100%;
      font-size: 28rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      color: #adadad;
      line-height: 28rpx;

      overflow: hidden;
      -webkit-line-clamp: 2;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
    .right_text1 {
      width: 100%;
      font-size: 28rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      overflow: hidden;
      -webkit-line-clamp: 2;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      color: white;
    }

    .right_time {
      width: 100%;
      //   position: absolute;
      //   bottom: 0;
      margin-top: 17rpx;
      font-size: 24rpx;
      color: #adadad;
      display: flex;
      align-items: center;

      image {
        width: 24rpx;
        height: 24rpx;
      }

      text {
        margin-left: 11rpx;
      }
    }
  }
  .item_left_clickView {
    margin-right: 24rpx;
    .item_left_click {
      width: 40rpx;
      height: 40rpx;
    }
    .item_left_clickable {
      width: 40rpx;
      height: 40rpx;
    }
  }
}

.bottom {
  width: 100%;
  height: 112rpx;
  background: #272727;
  position: fixed;
  bottom: 0;
  left: 0;
  padding: 16rpx 30rpx;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .bottom_left {
    display: flex;
    align-items: center;
    .item_left_click {
      width: 40rpx;
      height: 40rpx;
    }
    .bottom_left_text {
      margin-left: 16rpx;
      color: #eeeeee;
      font-size: 30rpx;
    }
  }

  .bottom_right {
    width: 250rpx;
    height: 80rpx;
    background: #ee6060;
    border-radius: 48rpx;
    text-align: center;
    line-height: 80rpx;
    font-size: 30rpx;
    color: #eeeeee;
  }
}

/deep/.u-modal__content__text {
  text-align: center;
}

.empty_view {
  margin-top: 300rpx;
  image {
    margin: 0 auto;
    width: 410rpx;
    height: 410rpx;
  }
  view {
    font-size: 30rpx;
    color: #d8d8d8;
    text-align: center;
  }
}
</style>